<?php
include ('common/constants.php');
include ('common/db.php');
session_start();

if ((!isset($_SESSION['user_email'])) || ($_SESSION['user_email']=='')) {
  header('location: login.php');
}

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Carpooling - Preferences</title>
<link href="resources/css/bootstrap.min.css" rel="stylesheet">
<link href="resources/css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="resources/css/datepicker.css" rel="stylesheet">
<link href="resources/css/jquery.timepicker.css" rel="stylesheet">
<style type="text/css">
.cus_row {
	-moz-box-sizing: border-box;
	float:left;
	min-height: 1px;
	padding-right: 15px;
	position: relative;
}
	body {
		padding-top: 40px;
		padding-bottom: 40px;
		background-color: #f5f5f5;
	}

      .form-signin {
        max-width: 80%;
        padding: 19px 29px 29px;
        margin: 0 auto 20px;
        background-color: #fff;
        border: 1px solid #e5e5e5;
        -webkit-border-radius: 5px;
           -moz-border-radius: 5px;
                border-radius: 5px;
        -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
           -moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
                box-shadow: 0 1px 2px rgba(0,0,0,.05);
      }
      .form-signin .form-signin-heading,
      .form-signin .checkbox {
        margin-bottom: 10px;
      }
      .form-signin input[type="text"],
      .form-signin input[type="password"] {
        font-size: 16px;
        height: auto;
        margin-bottom: 15px;
        padding: 7px 9px;
      }

</style>
</head>

<body>
<div class="navbar navbar-inverse navbar-fixed-top">
  <div class="navbar-inner">
    <div class="container"> 
    	  <?php 
  
		  $sql = " SELECT * FROM user_preference where email='". $_SESSION["user_email"]. "'";
		   
		  $result = mysql_query($sql) or trigger_error(mysql_error());
		  ?>
    	<a class="btn btn-navbar" style="margin-top: 25px;" data-toggle="collapse" data-target=".nav-collapse">
          <span class="icon-bar"></span> 
          <span class="icon-bar"></span> 
          <span class="icon-bar"></span> 
      	</a> <a class="brand" style="text-align:center;" href="home.php"><img src="resources/icons/share_ride.png" style="max-width:55px; padding-right:15px"/>Carpooling.lk</a>
      <div class="nav-collapse collapse">
        <ul class="nav navbar-nav">
          <li style="text-align:center; float:left">
            <a href="advertise.php"><img src="resources/icons/speaker.png" style="max-width:40px; min-width: 20px;"/><br />Advertise</a>
          </li>
          <li style="text-align:center; float:left">
          	<a href="publish.php"><img src="resources/icons/publish.png" style="max-width:40px; min-width: 20px;"/><br />Publish</a>
          </li>
          <li style="text-align:center; float:left">
          	<a href="#notifPanel" data-toggle="modal"><img src="resources/icons/notification.png" style="max-width:40px; min-width: 20px;"/><br />Notifications</a>
          </li>
          <li style="text-align:center; float:left">
          	<a href="my_posts.php"><img src="resources/icons/my_posts.png" style="max-width:40px; min-width: 20px;"/><br />My Posts</a>
          </li>
          <li style="text-align:center; float:left">
          	<a href="user_details.php"><img src="resources/icons/user_details.png" style="max-width:40px; min-width: 20px;"/><br />User Details</a>
          </li>
          <li class="active" style="text-align:center; float:left">
          	<a href="preferences.php"><img src="resources/icons/preferences.png" style="max-width:40px; min-width: 20px;"/><br />Preferences</a>
          </li>
          <li style="text-align:center; float:left">
          	<a data-toggle="collapse" data-target="#srch_panel"><img src="resources/icons/search.png" style="max-width:40px; min-width: 20px;"/><br />Search</a>
          </li>
          <li style="text-align:center; float:left; line-height: 0px; max-width: 200px;">
            &nbsp;&nbsp;<a class="" data-toggle="collapse"><h4>Hi <?php echo $_SESSION['user_name']?></h4></a><br />
          </li>
          <li style="text-align:center; float:left">
            &nbsp;&nbsp;<a style="padding:20px; margin: 0;" href="login.php">Sign Out</a>
          </li>
        </ul>
      </div>
      
	  <!-- Search Panel -->
  	  <div id="includedSrchPanel" class="cus_row" style="width:100%"></div>
      
    </div>
  </div>
</div>
<div style="height:42px"></div>

<div class="container">
  <h1>Preferences</h1>
    <form class="form-actions" name="pref" id="pref">
       
        <fieldset>
          <legend>Change Your Preferences</legend>
          
          <div class="control-group">
          
              <div style="width:100%;">

                    <label class="control-label" for="origin">Origin</label>
                    <div class="controls">
                    
                         <input id="origin" type="text" data-provide="typeahead" autocomplete="off" data-items="4" name="origin" data-source='["Colombo 1", "Colombo 2", "Colombo 3", "Colombo 4", "Colombo 5", "Colombo 6", "Colombo 7", "Colombo 8", "Colombo 9", "Colombo 10", "Colombo 11" ,"Colombo 12" ,"Colombo 13" ,"Colombo 14" ,"Colombo 15" ,"Athurugiriya" ,"Attidiya" ,"Battaramulla" ,"Biyagama" ,"Boralesgamuwa" ,"Dehiwala" ,"Galle" ,"Gampaha" ,"Ja-Ela" ,"Jawatta" ,"Jayawardanapura" ,"Kadawatha" ,"Kalalgoda" ,"Kalapaluwawa" ,"Kalubowila" ,"Kandana" ,"Kandy" ,"Katunayaka" ,"Kelaniya" ,"Kiribathgoda" ,"Kirulapone" ,"Kohuwala" ,"Kolonnawa" ,"Kottawa" ,"Kotte" ,"Kurunegala" ,"Mahabage" ,"Maharagama" ,"Malabe" ,"Matara" ,"Moratuwa" ,"Mount Lavinia" ,"Mulleriyawa" ,"Nawala" ,"Negombo" ,"Nugegoda" ,"Panadura" ,"Pannipitiya" ,"Peliyagoda" ,"Pepiliyana" ,"Polgasowita" ,"Ragama" ,"Rajagiriya" ,"Ratmalana" ,"Seeduwa" ,"Thalawatugoda" ,"Union Place" ,"Wattala"]' value="<?php echo mysql_result($result, 0, "origin") ?>">
                    </div>

                    <label class="control-label" for="destination">Destination</label>
                    <div class="controls">
                        <input id="destination" type="text" data-provide="typeahead" autocomplete="off" data-items="4" name="destination" data-source='["Colombo 1", "Colombo 2", "Colombo 3", "Colombo 4", "Colombo 5", "Colombo 6", "Colombo 7", "Colombo 8", "Colombo 9", "Colombo 10", "Colombo 11" ,"Colombo 12" ,"Colombo 13" ,"Colombo 14" ,"Colombo 15" ,"Athurugiriya" ,"Attidiya" ,"Battaramulla" ,"Biyagama" ,"Boralesgamuwa" ,"Dehiwala" ,"Galle" ,"Gampaha" ,"Ja-Ela" ,"Jawatta" ,"Jayawardanapura" ,"Kadawatha" ,"Kalalgoda" ,"Kalapaluwawa" ,"Kalubowila" ,"Kandana" ,"Kandy" ,"Katunayaka" ,"Kelaniya" ,"Kiribathgoda" ,"Kirulapone" ,"Kohuwala" ,"Kolonnawa" ,"Kottawa" ,"Kotte" ,"Kurunegala" ,"Mahabage" ,"Maharagama" ,"Malabe" ,"Matara" ,"Moratuwa" ,"Mount Lavinia" ,"Mulleriyawa" ,"Nawala" ,"Negombo" ,"Nugegoda" ,"Panadura" ,"Pannipitiya" ,"Peliyagoda" ,"Pepiliyana" ,"Polgasowita" ,"Ragama" ,"Rajagiriya" ,"Ratmalana" ,"Seeduwa" ,"Thalawatugoda" ,"Union Place" ,"Wattala"]' value="<?php echo mysql_result($result, 0, "destination") ?>">
                    </div>
              </div>
              
            <input type="hidden" name="email" id="email" value="<?php echo $_SESSION['user_email']?>" /> 
            
          <div class="form-actions cus_row" style="width:100%; padding-left: 0px;">
            <button type="button" class="btn btn-large btn-primary" id="preferences-btn">Save</button>
          </div>
        </fieldset>

    </form>
    
    <!-- Notification Panel -->
  	<div id="includedNotifPanel"></div>

  	<!-- Site footer -->
    <div class="navbar navbar-inverse navbar-fixed-bottom">
    	<div class="navbar-inner"> <a class="brand" href="#" style="padding-left:7%">&copy; Carpooling.lk 2013</a> </div>
    </div>
</div>

<!-- JAVASCRIPT INCLUDES -->
<script type="text/javascript" src="resources/js/jquery.min.js"></script>
<script type="text/javascript" src="resources/js/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="resources/js/bootstrap-modal.js"></script>
<script type="text/javascript" src="resources/js/bootstrap-transition.js"></script>
<script type="text/javascript" src="resources/js/bootstrap-collapse.js"></script>
<script type="text/javascript" src="resources/js/bootstrap-typeahead.js"></script>
<script type="text/javascript" src="resources/js/jquery.timepicker.js"></script>
<script type="text/javascript" src="common/admin.js"></script>

<script type="text/javascript">

	//Include Search panel
	$(function(){
      $("#includedSrchPanel").load("search_panel.php"); 
    });
	
	//Include Notification panel
	$(function(){
      $("#includedNotifPanel").load("notification_panel.php"); 
    });

 	function submitForm(){
      jQuery.ajax({
        url: 'savePreferences.php',
        type: "POST",
        data: $('#pref').serialize(),
        success: function(data) {
          if(data=="success"){
			alert("Preferences saved.");
            location.href="home.php";
          }else{  showMsg(data); }
        }
      });
    }

    $("#preferences-btn").bind('click', function(){
        submitForm();
    });
	

</script>
</body>
</html>